home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / lmemchr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  792 b   |  48 lines

  1. #ifdef __GNUC__
  2. #ifdef __MSHORT__
  3. #include "lib.h"
  4.  
  5. /*
  6.  * memchr - search for a byte
  7.  *
  8.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  9.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  10.  */
  11.  
  12. #ifdef NULL
  13. #undef NULL
  14. #endif
  15.  
  16. #define    NULL    0
  17.  
  18. #ifndef CHARBITS
  19. #    define    UNSCHAR(c)    ((unsigned char)(c))
  20. #    define  uchar        unsigned char
  21. #else
  22. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  23. #    define  uchar        char
  24. #endif
  25.  
  26. _VOIDSTAR
  27. lmemchr(s, ucharwanted, size)
  28. _CONST _VOIDSTAR s;
  29. int ucharwanted;
  30. long size;
  31. {
  32.     register _CONST uchar *scan;
  33.     register long n;
  34.     register int uc;
  35.  
  36.     scan = s;
  37.     uc = UNSCHAR(ucharwanted);
  38.     for (n = size; n > 0; n--)
  39.         if (UNSCHAR(*scan) == uc)
  40.             return((char *)scan);
  41.         else
  42.             scan++;
  43.  
  44.     return(NULL);
  45. }
  46. #endif /* __MSHORT__ */
  47. #endif /* __GNUC__   */
  48.